package com.mate.cloud.redisson.service;


import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 标签统计服务
 * @author:         MI
 * @email:          448341911@qq.com
 * @createTime:     2025/8/19 10:22
 * @updateUser:     MI
 * @updateTime:     2025/8/19 10:22
 * @updateRemark:   修改内容
 * @version:        1.0
 */
@Service
public class TagStatsService {

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    /**
     * 获取标签使用统计
     * @param tagName 标签名称
     * @return 使用次数
     */
    public long getTagUsageCount(String tagName) {
        String hotTagsKey = "tag:hot";
        Double score = redisTemplate.opsForZSet().score(hotTagsKey, tagName);
        return score == null ? 0 : score.longValue();
    }

    /**
     * 获取标签元数据
     * @param tagName 标签名称
     * @return 元数据Map
     */
    public Map<Object, Object> getTagMetadata(String tagName) {
        String metaKey = "tag:metadata:" + tagName;
        return redisTemplate.opsForHash().entries(metaKey);
    }
}
